import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import { systemid, productid } from '../../atom/config';
export default async function a005(fd: IFeidaoAiBrowserComponent) {
	// todo
	const staff_no = get(fd, "staff_no1");
	const staff_name = get(fd, "staff_name1");
	const project_no = get(fd, "project_no");
	const project_name = get(fd, "project_name");
	if (!project_name) {
		alert("请选择项目名称!");
		return;
	}
	const project_manager = get(fd, "project_manager");
	const equip_depart_name = get(fd, "equip_depart_name");
	const risk_type1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_type"]');
	const risk_type = risk_type1.selectedIndex;
	if (!risk_type) {
		alert("请选择风险类型!");
		return;
	}
	const involved_amount1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="involved_amount"]');
	const involved_amount = involved_amount1.value;
	if (!involved_amount) {
		alert("请填写涉及金额!");
		return;
	}
	if (!/^[0-9]*$/.test(involved_amount)) {
		alert("金额请输入数字!");
		return;
	}
	const risk_status1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_status"]');
	const risk_status = risk_status1.selectedIndex;
	if (!risk_status) {
		alert("请选择风险状态!");
		return;
	}
	const create_time = Date.now();
	const risk_content1 = fd.data.node.querySelector<HTMLTextAreaElement>('[data-id="risk_content"]');
	const risk_content = risk_content1.value;
	if (!risk_content) {
		alert("请填写风险内容!");
		return;
	}
	const memo1 = fd.data.node.querySelector<HTMLTextAreaElement>('[data-id="memo"]');
	const memo2 = memo1.value;
	let memo = "";
	if (memo2 !== "") {
		memo = memo2;
	}
	const res = await nodejs<{ code: 0 | 1; result: string }>('risk-control/zj-000002/s001', {
		filter: {
			risk_type,
			risk_content,
			risk_status,
			project_no,
			project_name,
			create_time,
			staff_no,
			staff_name,
			productid,
			involved_amount,
			memo
		}
	});
	const res1 = await nodejs<{ code: 0 | 1; result: string }>('risk-control/zj-000002/s002', {
		filter: {
			project_manager,
			equip_depart_name
		}
	});
	console.log("res66", res.code);
	if (res.code === 1 && res1.code === 1) {
		alert("添加成功");
		const ad = fd.data.node.querySelector<HTMLDivElement>('[data-id="add"]');
		set_node_cls(ad, 'display-n', true);
		fire('zj-000001', 'a004');
		fire('zj-000001', 'a005');
		const project_name1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="project_name"]');
		project_name1.value = "";
		const project_manager1 = fd.data.node.querySelector<HTMLSpanElement>('[data-id="project_manager"]');
		project_manager1.textContent = "";
		const equip_depart_name1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="equip_depart_name"]');
		equip_depart_name1.textContent = "";
		const risk_type1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_type"]');
		risk_type1.value = "0";
		const involved_amount1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="involved_amount"]');
		involved_amount1.value = "";
		const risk_status1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="risk_status"]');
		risk_status1.value = "0";
		const risk_content1 = fd.data.node.querySelector<HTMLTextAreaElement>('[data-id="risk_content"]');
		risk_content1.value = "";
		const memo1 = fd.data.node.querySelector<HTMLTextAreaElement>('[data-id="memo"]');
		memo1.value = "";
	} else {
		alert("添加失败");
	}
}

